<!doctype html>
<%@ page language="java" import="java.util.*" contentType="text/html;charset=utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<html class="">
<head>
<meta charset="utf-8">
<base href="<%=basePath%>">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="target-densitydpi=device-dpi, width=640, user-scalable=no">
<link href="assets/css/sstmobi/sstmobi.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="assets/js/jquery.js"></script>
<script type="text/javascript">
$(function () {
    var DEFAULT_WIDTH = 640, // 页面的默认宽度
        ua = navigator.userAgent.toLowerCase(), // 根据 user agent 的信息获取浏览器信息
        deviceWidth = window.screen.width, // 设备的宽度
        devicePixelRatio = window.devicePixelRatio || 1, // 物理像素和设备独立像素的比例，默认为1
        targetDensitydpi;

    // Android4.0以下手机不支持viewport的width，需要设置target-densitydpi
    //if (ua.indexOf("android") !== -1 && parseFloat(ua.slice(ua.indexOf("android")+8)) < 4) {
        targetDensitydpi = DEFAULT_WIDTH / deviceWidth * devicePixelRatio * 160;
        $('meta[name="viewport"]').attr('content', 'target-densitydpi=' + targetDensitydpi +
                ', width=640px, user-scalable=no');
    //}

    // TODO: 其他手机需要特殊处理的在下面
});
</script>
<script type="text/javascript" src="assets/js/zepto.min.js"></script>
<script type="text/javascript" src="http://g.alicdn.com/dingding/dingtalk-pc-api/2.3.1/index.js">
</script>
<script type="text/javascript" src="assets/js/logger.js">
</script>
<script type="text/javascript" >
/**
 * Created by linxinkai on 8/10/15.
 */

/**
 * _config comes from server-side template. see views/index.jade
 */
var _config = ${config};
DingTalkPC.config({
			agentId : _config.agentid,
			corpId : _config.corpId,
			timeStamp : _config.timeStamp,
			nonceStr : _config.nonceStr,
			signature : _config.signature,
			jsApiList : ['device.notification.alert', 'device.notification.confirm', 'runtime.permission.requestAuthCode']
		});
DingTalkPC.ready(function(res) {
	DingTalkPC.runtime.permission.requestAuthCode({
		corpId : _config.corpId,
		onSuccess : function(info) {
			$.ajax({
				url : 'userinfo?code=' + info.code + '&corpid='
						+ _config.corpId,
				type : 'GET',
				success : function(data, status, xhr) {
					var info = JSON.parse(data);
					$.post("rest/dingding/visitorpc/query", {
						corpid : _config.corpId,
						appid : _config.appid,
						userid : info.userid
					}, function(json) {
						var success = json.success;
						if(success){
							var pageList = json.pageList;
							var html = "";
							for(var i = 0; i < pageList.length;i++){
								var ar = pageList[i];
								var result_css = "";
								if(ar.approvalStatus == "核准中"){
									result_css = "result_1";
								} else if(ar.approvalStatus == "核准"){
									result_css = "result_3";
								} else {
									result_css = "result_2";
								}
								html = html + "<a href='rest/dingding/visitorapp/getinfo?corpid="+_config.corpId +"&appid="+_config.appid+"&visitorId=" +ar.id+
								"&accessToken=${accessToken}'><div class='GenStuBox'> <div class='GstuInfo'>" +
								"<div class='GstuName'>"+ar.name+"<span class='"+result_css+"'>"+ar.approvalStatus+"</span></div> <div class='GstuSubInfo'>"+ ar.time + ar.info+"</div></div></div></a>"; 
							}
							$("#body").append(html);
						} else {
							alert(222);
						}
						
					},"json");
				},
				error : function(xhr, errorType, error) {
					logger.e("yinyien:" + _config.corpId);
					alert(errorType + ', ' + error);
				}
			});
		},
		onFail : function(err) {
			alert('fail: ' + JSON.stringify(err));
		}
	});
});
DingTalkPC.error(function(err) {
	alert('dd error: ' + JSON.stringify(err));
});

</script>
 
<title>首页</title>
</head>
<body style="background:#FFF;">


<div class="view">
<div class="scroll-wrap">

<div class="MainBody">

<!-- 	<div class="IncHeader"> -->
<!--     	<div class="H_Back"></div> -->
<!--         <div class="H_Tit">访客记录</div> -->
<!--         <div class="H_Send">搜索</div> -->
<!--     </div> -->
    
    <div id="body" class="IncBodyer">
    </div>

</div>


</div>
</div>



</body>
</html>
